////////////
//Namen: funkcije za preprost sql i/o
////////////
include('server/player/player.lua')

//CreateConVar("GreenRP_sql_error_reporting", "1", { FCVAR_REPLICATED })

//function SQL_ErrorCheck()
//	if (GetConVar("GreenRP_sql_error_reporting":GetBool() == true) then
//		if ( sql.LastError() != nil ) then
//			Msg("GREENRP SQL ERROR: " .. sql.LastError() .. "\n")
//		end
//	end
//end

function SQL_Init()
	if !sql.TableExists("sql_player_table") then
		sql.Query("CREATE TABLE sql_player_table ( unique_id varchar(255), money int, model text, inventory text )")
		//SQL_ErrorCheck()
	end
end

function SQL_RegisterNewPlayer( steamID )
	Msg("Registering new player!!!!!!!!")
	sql.Query("INSERT INTO sql_player_table (`unique_id`, `money`, `model`, `inventory` )VALUES ('"..steamID.."', '1000', '', 'weapon_pistol')")
	//SQL_ErrorCheck()
end

function SQL_WriteValue( steamID, money, model, inventory )
	sql.Query("UPDATE sql_player_table SET money = "..money..", model = '"..model.."', inventory = '"..inventory.."' WHERE unique_id = '"..steamID.."'")
	//SQL_ErrorCheck()
end 

function SQL_ReadValue( steamID, variable )
	Msg("VARIABLE: " .. variable .. "\n")
	local result = sql.QueryValue("SELECT "..variable.." FROM sql_player_table WHERE unique_id = '"..steamID.."'")
	//SQL_ErrorCheck()
	//Msg(sql.LastError() .. "\n")
	return result
end
